/*
 * @Author       : NaN 353362604@qq.com
 * @Date         : 2023-05-17 14:44:18
 * @LastEditTime : 2023-09-11 14:22:12
 * @LastEditors  : 飞越疯人院 353362604@qq.com
 * @FilePath     : \AdminStration\src\Common\Router\MenuNav\module\DescriptionsModal.jsx
 * @Description  :
 */
import { useState } from 'react'
import { Descriptions } from 'antd'
import { findValue } from '../../../Configure/Common'
import { useEffect } from 'react'
const HiddenList = ['hidden', 'systemOperation', 'SearchSort']

const HiddenIndex = {
    Sample: [
        'clientOrganization',
        'engineeringName',
        'organizationUuid',
        'createUserName',
        'createTime',
        'updateUserName',
        'updateTime',
        'paymentMethod',
    ],
}

export const DescriptionsModal = ({ data, pageHeaderData, type }) => {
    const [items, setItems] = useState([])
    useEffect(() => {
        let headerData = []
        pageHeaderData.forEach(item => {
            const { dataIndex, title, valueType, valueEnum, fieldProps, hideInTable, hideInHeader, render } = item
            if (
                dataIndex &&
                !HiddenList.includes(valueType) &&
                !hideInTable &&
                !hideInHeader &&
                (!HiddenIndex[type] || !HiddenIndex[type].includes(dataIndex))
            ) {
                headerData = [
                    ...headerData,
                    {
                        key: dataIndex,
                        label: title,
                        children: (() => {
                            switch (valueType) {
                                case 'select':
                                    return valueEnum[data[dataIndex]]?.text || valueEnum[data[dataIndex]] || '~'
                                case 'treeSelect':
                                    return findValue(fieldProps.options, 'uuid', data[dataIndex])?.tableName || '~'
                                case 'render':
                                    return render('', data)
                                default:
                                    return data[dataIndex] || '~'
                            }
                        })(),
                    },
                ]
            }
        })
        setItems(headerData)
    }, [data, pageHeaderData, type])
    return <Descriptions bordered size="small" layout="vertical" className="pageHeaderData" items={items} />
}
